export default {
  data () {
    return {
      PM2GaugeEchart: null,
      PM2GaugeOption: {
        series: [
          {
            name: 'PM2.5',
            type: 'gauge',
            detail: {formatter:'{value}'},
            radius: '85%',
            max: 500,
            splitNumber: 10,
            splitLine: {
              lineStyle: {
                color: '#fff'
              }
            },
            title: {
              fontSize: 18,
              offsetCenter: [0, '-30%'],
              fontWeight: 'bolder'
            },
            axisTick: {
              lineStyle: {
                color: '#fff'
              }
            },
            pointer: {
              width: 4
            },
            axisLine: {
              show: true,
              lineStyle: {
                width: 15,
                shadowBlur: 0,
                color: [[0.2, '#30d394'],[0.8, '#ffdeb1'],[1, '#fea8a9']]
              }
            },
            data: [{value: 50, name: 'PM2.5'}]
          }
        ]
      }
    }
  },
  methods: {
    initPM2GaugeEchart () {
      let alarm = 1
      let color = [[0.2, '#85e7c2'], [0.8, '#ffdeb1'], [1, '#ffe2e2']]
      let PMTWOPOINTFIVEWARN = Number.parseInt(this.groupParams.PMTWOPOINTFIVEWARN || 0)
      let PMTWOPOINTFIVEALARM = Number.parseInt(this.groupParams.PMTWOPOINTFIVEALARM || 0)
      let max = PMTWOPOINTFIVEALARM + 50
      let normal = PMTWOPOINTFIVEWARN / max
      let warngin = ((PMTWOPOINTFIVEALARM - PMTWOPOINTFIVEWARN) / max) + normal
      if (this.projectEnvironmentData.pmTwoPointFive < PMTWOPOINTFIVEWARN) {
        let pmTwo = this.projectEnvironmentData.pmTwoPointFive / PMTWOPOINTFIVEWARN
        let pmNormal = normal * pmTwo
        color = [[pmNormal, '#30d394'], [normal, '#85e7c2'], [warngin, '#fff6ed'], [alarm, '#ffe3e1']]
      }
      // 预警状态
      if (this.projectEnvironmentData.pmTwoPointFive > PMTWOPOINTFIVEWARN && this.projectEnvironmentData.pmTwoPointFive < PMTWOPOINTFIVEALARM) {
        let pmTwo = this.projectEnvironmentData.pmTwoPointFive / max
        color = [[normal, '#30d394'], [pmTwo, '#fda730'], [warngin, '#ffdeb1'], [alarm, '#fea8a9']]
      }
      // 报警
      if (this.projectEnvironmentData.pmTwoPointFive > PMTWOPOINTFIVEALARM) {
        let pmTwo = this.projectEnvironmentData.pmTwoPointFive / max
        color = [[normal, '#30d394'], [warngin, '#fea831'], [pmTwo, '#fa5655'], [alarm, '#ffe2e2']]
      }
      this.PM2GaugeOption.series[0].axisLine.lineStyle.color = color
      this.PM2GaugeOption.series[0].data = []
      this.PM2GaugeOption.series[0].max = max
      this.PM2GaugeOption.series[0].data.push({value: this.projectEnvironmentData.pmTwoPointFive || 0, name: 'PM2.5\n(ug/m³)'})
      this.PM2GaugeEchart = this.$Echarts.init(this.$refs.gaugeEnvironment)
      this.PM2GaugeEchart.setOption(this.PM2GaugeOption)
    }
  }
}
